/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.interpreter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author Laurent WOUTERS
 */
public class XOWLException extends java.lang.Exception {
    protected Thread thread;
    protected String file;
    protected int line;
    protected String message;
    protected List<String> stack;

    public Thread getThread() { return thread; }
    public void setThread(Thread thread) { this.thread = thread; }
    public String getFile() { return file; }
    public void setFile(String file) { this.file = file; }
    public int getLine() { return line; }
    public void setLine(int line) { this.line =line; }
    public Collection<String> getStack() { return stack; }

    public String getHeadline() { return "XOWL VM Runtime Error: " + file + "@" + line + ": " + message; }

    public XOWLException(String message) {
        this.file = "Unknown";
        this.stack = new ArrayList<String>();
        this.message = message;
    }
    public XOWLException(java.lang.Exception ex) {
        super(ex);
        file = "Unknown";
        stack = new ArrayList<String>();
        message = "Java exception";
    }

    public void addStackElement(String element) { stack.add(element); }

    public void printXOWLStack() {
        java.lang.System.err.println(getHeadline());
        for (String elem : stack)
            java.lang.System.err.println("\tat " + elem);
    }
}
